package cn.edu.zafu.bigdata.x.wgj.i;

import java.net.SocketOption;

class Counter{
    public static final Object lock=new Object();
    public static final Object lock2=new Object();
    public static int count=0;
}
class AddThread extends Thread{
    public void run(){
        synchronized (Counter.lock){
            for(int i=0;i<10000;i++){
                Counter.count += 1;
            }
        }
    }
}
class DecThread extends Thread{
    public void run(){
        synchronized (Counter.lock2){
            for(int i=0;i<10000;i++){Counter.count -= 1;}
        }
    }
}
public class ThreadDemo4 {
    public static void main(String[] args) throws InterruptedException {
        var add=new AddThread();
        var dec=new AddThread();
        add.start();
        dec.start();
        add.join();
        dec.join();
        System.out.println(Counter.count);
    }
}
